package game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;


public class MenuPanel extends javax.swing.JPanel {

	private Game frame;
	private Image img;
	
    /** Creates new form IceCubeMenu */
    public MenuPanel(Game pframe) {
        initComponents();
        this.frame = pframe;
        this.setOpaque(true);
        
        this.setBackground(Color.white);
		this.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 800,
				600, new ImageIcon(getClass().getResource(
						"/images/menu_background.png"))));
        ImageIcon ii = new ImageIcon(this.getClass().getResource("/images/menu_background.png"));
        this.img = ii.getImage();
       
    }
    
//    public void paint(Graphics g){
//    	g.drawImage(img, 0, 0, null);
//    	this.validate();
//    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        btn_exit = new javax.swing.JButton();
        btn_Credits = new javax.swing.JButton();
        btn_playLevel = new javax.swing.JButton();
        btn_newGame = new javax.swing.JButton();
        btn_continue = new javax.swing.JButton();

        btn_exit.setText("Exit");
        btn_exit.setToolTipText("Exit Ice Cube");
        btn_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_exitActionPerformed(evt);
            }
        });

        btn_Credits.setText("Credits");
        btn_Credits.setToolTipText("Show the credits");
        btn_Credits.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CreditsActionPerformed(evt);
            }
        });

        btn_playLevel.setText("Play Level");
        btn_playLevel.setToolTipText("Select a Level to play");
        btn_playLevel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_playLevelActionPerformed(evt);
            }
        });

        btn_newGame.setText("New Game");
        btn_newGame.setToolTipText("Start a new Game!");
        btn_newGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_newGameActionPerformed(evt);
            }
        });

        btn_continue.setText("Continue");
        btn_continue.setToolTipText("Continue from last Level");
        btn_continue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_continueActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(132, 132, 132)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_continue)
                    .addComponent(btn_newGame)
                    .addComponent(btn_playLevel)
                    .addComponent(btn_Credits)
                    .addComponent(btn_exit, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(158, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(125, Short.MAX_VALUE)
                .addComponent(btn_continue)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_newGame)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_playLevel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_Credits)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_exit)
                .addContainerGap())
        );
        
        this.validate();
    }// </editor-fold>

    private void btn_newGameActionPerformed(java.awt.event.ActionEvent evt) {
        this.setVisible(false);
        GamePanel gp = new GamePanel(0, 800, 600, frame);
        
        frame.add(gp);   
        frame.remove(this);
        frame.validate();
    }

    private void btn_continueActionPerformed(java.awt.event.ActionEvent evt) {
        this.setVisible(false);
        GamePanel gp = new GamePanel(Game.lastLevel, 800, 600, frame);
        
        frame.add(gp);   
        frame.remove(this);
        frame.validate();
    }

    private void btn_playLevelActionPerformed(java.awt.event.ActionEvent evt) {
        this.setVisible(false);
        LoadLevelPanel load = new LoadLevelPanel(frame);
        
        frame.add(load);   
        frame.remove(this);
        frame.validate();
    }

    private void btn_CreditsActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void btn_exitActionPerformed(java.awt.event.ActionEvent evt) {
    	//maybe ask to exit first?
    	frame.exitIceCube();
    }


    // Variables declaration - do not modify
    private javax.swing.JButton btn_Credits;
    private javax.swing.JButton btn_continue;
    private javax.swing.JButton btn_exit;
    private javax.swing.JButton btn_newGame;
    private javax.swing.JButton btn_playLevel;
    // End of variables declaration

}
